/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cor;

import general.MessageHandler;
import general.UDPMessage;

/**
 *
 * @author foliveira
 */
public class AvaliableHandler extends MessageHandler {

  private String host;
  
  @Override
  public boolean accept(UDPMessage message) {
    this.setRequest(message.getText());

    // atualizada 
    if ( getRequest().getCommand().contains("AVALIABLE") ) 
      return true;
    else
      return false;
    
    
  }

   
  @Override
  public void doHandle(UDPMessage message) {
    //this.setRequest(message.getText());
    
    try {
      
      // atualiza host
      setHost(String.format("%s:%s",message.getPacket().getAddress().getHostName(),
              message.getPacket().getPort() ));
      
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  public String getHost() {
    return host;
  }

  public void setHost(String host) {
    this.host = host;
  }
}
